(function (dom) {
    let domEle = {
        nav_ul: dom.getElementById('nav_ul'),
        sub_nav: dom.getElementById('sub_nav'),
        search: dom.getElementById('search'),
        search_main: dom.getElementById('search_main'),
        inner_close: dom.getElementById('inner_close'),
        user_info: dom.getElementById('user_info'),
        user_drop: dom.getElementById('user_drop'),
        banner: dom.getElementById('banner'),
        carousel: dom.getElementById('carousel'),
        usernameDiv: dom.querySelector('.username'),
        pwdDiv: dom.querySelector('.password'),
        username: dom.querySelector('#username'),
        pwd: dom.querySelector('#password'),
        reg_usernameDiv: dom.querySelector('.reg_username'),
        reg_pwdDiv: dom.querySelector('.reg_password'),
        reg_username: dom.querySelector('#reg_username'),
        reg_pwd: dom.querySelector('#reg_password'),
        go_login: dom.querySelector('#go_login'),
        go_register: dom.querySelector('#go_register'),
        login_box: dom.querySelector('.login_box'),
        register_box: dom.querySelector('.register_box'),
        close: dom.querySelectorAll('.close'),
        mask: dom.querySelector('.mask'),
        go_login_mask: dom.querySelector('#go_login_mask')
    }
    let domFun = {
        nav_ul_addELFun: function (dom, event) {
            dom.addEventListener(event, function () {
                if (domEle.sub_nav.style.visibility == "visible") {
                    domEle.sub_nav.style.visibility = 'hidden';
                } else {
                    domEle.sub_nav.style.visibility = 'visible';
                }
            })
        },
        sub_nav_VisFun: function () {
            domFun.nav_ul_addELFun(domEle.nav_ul, 'mouseover');
            domFun.nav_ul_addELFun(domEle.nav_ul, 'mouseout');
            domFun.nav_ul_addELFun(domEle.sub_nav, 'mouseover');
            domFun.nav_ul_addELFun(domEle.sub_nav, 'mouseout');
        },
        search_main_DisFun: function () {
            domEle.search.addEventListener('click', function () {
                setTimeout(function () {
                    domEle.search_main.style.opacity = 1;
                }, 0)
                domEle.search_main.style.display = "block";
            })
            domEle.inner_close.addEventListener('click', function () {
                domEle.search_main.style.opacity = 0;
                setTimeout(function () {
                    domEle.search_main.style.display = "none";
                }, 500)
            })
        },
        user_info_addELFun: function (dom, event) {
            dom.addEventListener(event, function () {
                if (domEle.user_drop.style.display == "block") {
                    domEle.user_drop.style.display = "none";
                } else {
                    domEle.user_drop.style.display = "block";
                }
                domEle.user_info.classList.toggle("rgba9");
            })
        },
        user_info_moo: function () {
            domFun.user_info_addELFun(domEle.user_info, 'mouseover');
            domFun.user_info_addELFun(domEle.user_info, 'mouseout');
            domFun.user_info_addELFun(domEle.user_drop, 'mouseover');
            domFun.user_info_addELFun(domEle.user_drop, 'mouseout');
        },
        bannerOnscroll: function () {
            window.onscroll = function () {
                domEle.banner.style.height = "350px";
                domEle.banner.style.background = "url(public/img/pic-back-v14.jpg) no-repeat center -10px";
                window.onscroll = '';
            }
        },
        carouselFun: function () {
            let width = 820;
            let num = 0;
            let items = dom.getElementsByClassName('nav_carousel_item');
            let carousel = function () {
                items[num].classList.remove('on');
                num += 1;
                if (num > 4) {
                    num = 0;
                }
                domEle.carousel.style.marginLeft = -(num * width) + "px";
                items[num].classList.add('on');
            }
            let setI = setInterval(carousel, 3000);
            for (let i = 0; i < items.length; i++) {
                items[i].addEventListener('mouseover', function () {
                    clearInterval(setI);
                    items[num].classList.remove('on');
                    num = i;
                    domEle.carousel.style.marginLeft = -(num * width) + "px";
                    items[num].classList.add('on');
                })
                items[i].addEventListener('mouseout', function () {
                    setI = setInterval(carousel, 3000);
                })
            }
        },
        hero_nav_Hover: function () {
            let hero_nav = dom.getElementsByClassName('hero_nav');
            let hero_content = dom.getElementsByClassName('hero_content');
            for (let i = 0; i < hero_nav.length; i++) {
                hero_nav[i].addEventListener('mouseover', function () {
                    for (let i = 0; i < hero_nav.length; i++) {
                        hero_nav[i].classList.remove('current');
                        hero_content[i].style.display = 'none';
                    }
                    hero_nav[i].classList.add('current');
                    hero_content[i].style.display = 'block';
                })
            }
        },
        hero_img_Hover: function () {
            let hero_img = dom.getElementsByClassName('hero_img');
            let hero_mask = dom.getElementsByClassName('hero_mask');
            for (let i = 0; i < hero_img.length; i++) {
                hero_img[i].addEventListener('mouseover', function () {
                    hero_mask[i].style.display = 'block';
                })
                hero_img[i].addEventListener('mouseout', function () {
                    hero_mask[i].style.display = 'none';
                })
                hero_mask[i].addEventListener('mouseover', function () {
                    hero_mask[i].style.display = 'block';
                })
                hero_mask[i].addEventListener('mouseout', function () {
                    hero_mask[i].style.display = 'none';
                })
            }
        },
        consultation_nav_Fun: function(){
            let consultation_nav = dom.getElementsByClassName('consultation_nav');
            let news_content = dom.getElementsByClassName('news_content');
            for (let i = 0; i < consultation_nav.length;i++){
                consultation_nav[i].addEventListener('mouseover',function(){
                    for (let j = 0; j < news_content.length; j++) {
                        consultation_nav[j].classList.remove('current');
                        news_content[j].style.display = "none";
                    }
                    consultation_nav[i].classList.add('current');
                    news_content[i].style.display = "block";
                })
            }
        },
        news_hover_Fun: function(){
            let news_item = dom.getElementsByClassName('news_item');
            let news_type = dom.getElementsByClassName('new_type');
            for(let i = 0;i<news_item.length;i++){
                news_item[i].addEventListener('mouseover',function(){
                    news_item[i].style.color = "#d1ab57";
                    news_type[i].classList.add('news_current');
                })
                news_item[i].addEventListener('mouseout', function () {
                    news_item[i].style.color = "#555555";
                    news_type[i].classList.remove('news_current');
                })
            }
        },
        loginFun: function(){
            domEle.username.addEventListener('focus',function(){
                domEle.usernameDiv.style.backgroundPosition = "-1px -45px";
            })
            domEle.username.addEventListener('blur',function(){
                domEle.usernameDiv.style.backgroundPosition = "-1px -1px";
            })
            domEle.pwd.addEventListener('focus',function(){
                domEle.pwdDiv.style.backgroundPosition = "-1px -45px";
            })
            domEle.pwd.addEventListener('blur',function(){
                domEle.pwdDiv.style.backgroundPosition = "-1px -1px";
            })

             domEle.reg_username.addEventListener('focus',function(){
                domEle.reg_usernameDiv.style.backgroundPosition = "-1px -45px";
            })
            domEle.reg_username.addEventListener('blur',function(){
                domEle.reg_usernameDiv.style.backgroundPosition = "-1px -1px";
            })
            domEle.reg_pwd.addEventListener('focus',function(){
                domEle.reg_pwdDiv.style.backgroundPosition = "-1px -45px";
            })
            domEle.reg_pwd.addEventListener('blur',function(){
                domEle.reg_pwdDiv.style.backgroundPosition = "-1px -1px";
            })

            domEle.go_register.addEventListener('click',function(){
                domEle.login_box.style.display = 'none';
                domEle.register_box.style.display = 'block';
            })
            domEle.go_login.addEventListener('click',function(){
                domEle.login_box.style.display = 'block';
                domEle.register_box.style.display = 'none';
            })
            // console.log(close.length)
            for(let i=0;i<domEle.close.length;i++){
                domEle.close[i].addEventListener('click',function(){
                    domEle.mask.style.display = 'none';
                })
            }
            domEle.go_login_mask.addEventListener('click',function(){
                domEle.mask.style.display = 'flex';
            })
        }
    }
    domFun.sub_nav_VisFun();
    domFun.search_main_DisFun();
    domFun.user_info_moo();
    domFun.bannerOnscroll();
    domFun.carouselFun();
    domFun.hero_nav_Hover();
    domFun.hero_img_Hover();
    domFun.consultation_nav_Fun();
    domFun.news_hover_Fun();
    domFun.loginFun();
})(document)